#include "FrequenceDecode.h"
#include "common.h"
#define FrequencyDecodeCycleTime	(1)
#define FrequencyDecodeEdgeType		(0)//0:上升沿 1：下降沿
#define FrequencyDecode1sCnt		(1000/FrequencyDecodeCycleTime)
structFrequencyDecode stFrequencyDecodeEgine={0};
void vProcFrequencyDecode(structFrequencyDecode *pStFrequencyDecode,UINT8 u8DigitalInput)//1ms
{
	if(pStFrequencyDecode->u8DigitalInputLast!=u8DigitalInput)
	{
		#if (FrequencyDecodeEdgeType == 0)
		if(pStFrequencyDecode->u8DigitalInputLast==0)//上升边沿
		#else
		if(pStFrequencyDecode->u8DigitalInputLast!=0)//下降边沿
		#endif
		{
			if(pStFrequencyDecode->u16_1s_EdgeNumCnt<0xffff)
			{
				pStFrequencyDecode->u16_1s_EdgeNumCnt++;
			}
			pStFrequencyDecode->u16FrequencyOut2 = FrequencyDecode1sCnt/
			((pStFrequencyDecode->u16_2Edge_TimeCnt==0)?(1):(pStFrequencyDecode->u16_2Edge_TimeCnt));
			pStFrequencyDecode->u16_2Edge_TimeCnt = 0;
		}
		pStFrequencyDecode->u8DigitalInputLast=u8DigitalInput;
	}
	else
	{
		if(pStFrequencyDecode->u16_2Edge_TimeCnt<0xffff)
		{
			pStFrequencyDecode->u16_2Edge_TimeCnt++;
		}
	}
	if(pStFrequencyDecode->u16_1s_Cnt<FrequencyDecode1sCnt)
	{
		pStFrequencyDecode->u16_1s_Cnt++;
	}
	else
	{
		pStFrequencyDecode->u16_1s_Cnt = 0;
		pStFrequencyDecode->u16FrequencyOut1 = pStFrequencyDecode->u16_1s_EdgeNumCnt;
		pStFrequencyDecode->u16_1s_EdgeNumCnt=0;
	}
}

